# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=cmd2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.5.11
pkgrel=1
pkgdesc="Extra features for standard library's cmd module (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://cmd2.readthedocs.io/'
msys2_repository_url='https://github.com/python-cmd2/cmd2/'
msys2_references=(
  'purl: pkg:pypi/cmd2'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyperclip"
         "${MINGW_PACKAGE_PREFIX}-python-pyreadline3"
         "${MINGW_PACKAGE_PREFIX}-python-wcwidth")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
              "${MINGW_PACKAGE_PREFIX}-python-mock")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha512sums=('acf3d339d33822827be85b23491b99c33556bbd1d67715450c19c8877f7b9565253a402e57afd95bf02bb5edf8ec09f9fe7c141e01d81010286a5cfabca27909')

build() {
  export SETUPTOOLS_SCM_PRETEND_VERSION="${pkgver}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"
  python -m pytest || warning "Tests failed"
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
